﻿using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using iOSClub.Toolkit.WindowApp.Models;

namespace iOSClub.Toolkit.WindowApp.MemberControls;

public class MemberTemplate : IDataTemplate
{
    public Control Build(object? param)
    {
        if (param is not iOSManageItem item) return new TextBlock();
        var name = $" iOSClub.Toolkit.WindowApp.MemberControls.{item.Name}Control";
        var type = Type.GetType(name);
        if(type == null) return new TextBox();
        return (Control)Activator.CreateInstance(type)!;
    }

    public bool Match(object? data) => data is iOSManageItem;
}